Code for LinkedIn
Write object-oriented code to implement the design of the LinkedIn problem.
We've gone over the different aspects of LinkedIn and observed the attributes attached to the problem using various UML diagrams. Let’s explore the more practical side of things, where we will work on implementing the LinkedIn network using multiple languages. This is usually the last step in an object-oriented design interview process.
We have chosen the following languages to write the skeleton code of the different classes present in LinkedIn:
Java
C#
Python
C++
JavaScript
LinkedIn classes#
In this section, we will provide the skeleton code of the classes designed in the class diagram lesson.
Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public method functions.
Constants#
The following code provides the definition of the various enums and custom data types being used in the LinkedIn design:
Note: JavaScript does not support enumerations so we will be using the
Object.freeze()
method as an alternative that freezes an object and prevents further modifications.
Account#
The Account
class refers to an account of a user on LinkedIn. It includes their personal details, such as username, password, etc. It also allows users to reset their existing passwords. The definition of this class is given below:
Person, admin, and user#
The Person
class is an abstract class and contains details like the name, address, phone number, and email. It is derived into the Admin
and User
class.
Recommendation, achievement, and analytics#
The Recommendation
, Achievement
, and Analytics
classes will provide a user's personal information and make up the Profile
class. The definition of these classes is given below:
Profile, experience, education, and skill#
The Experience
, Education
, and Skill
classes will provide a user's personal information and make up the Profile
class. The definition of these classes is given below:
Company, job, and group#
LinkedIn users can create groups and company pages. The company page contains information about the company. The company pages will host various job postings. The Job
, CompanyPage
, and Group
classes are shown below:
Post, comment, message, and connection invitation#
LinkedIn users can create posts and comments. They can also send messages and connection invitations to other users. The definition of Post
, Comment
, Message
, and ConnectionInvitation
classes is given below:
Search, catalog, and notification#
The SearchCatalog
class contains information on users, company pages, groups, and jobs. It also implements the Search
interface class to enable the search functionality based on the given criteria (user, company page, group, and job keywords).
The Notification
class is responsible for sending notifications to users about any new messages, comments, posts, or connection invitations via the built-in notification option.
The definition of these classes is given below:
Wrapping up#
We've explored the complete design of LinkedIn in this chapter. We've looked at how LinkedIn can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.
Activity Diagram for LinkedIn
Interview Tips